package com.caozf.singleton.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 创建时间：2019/9/13 16:11
 * 创建人:曹子方
 */
public class ContainerSingleton {
    private ContainerSingleton() {
    }
    private static Map<String,Object> ioc=new ConcurrentHashMap<String,Object>();
    public static  Object getInstance(String className){
        try {
            if(className!=null){
                if(!ioc.containsKey(className)){
                    synchronized (ContainerSingleton.class){
                        if(!ioc.containsKey(className)){
                            Object obj=Class.forName(className).newInstance();
                            ioc.put(className,obj);
                        }
                    }
                }
                return ioc.get(className);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
